<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/4/20 0020
 * Time: 上午 11:21
 */
class Base_Model extends CI_Model
{
    public function __construct(){
        parent::__construct();
    }


    public function img($img='')
    {
        if(!empty($img))
        {
            return "http://www.wayatrip.com/".$img;
        }
        return '';
    }
    public function getUserInfoById($uid)
    {
        $key_info = array("telActive","identityErea_zhuanye", "identityErea_school","userIcon", "identityActive", "active", 'telCode', 'telNum', 'identityErea', 'identityName', 'identityPicture', 'email', 'failMsg', 'utype');
        $key_user_info = array('userAge', 'nationality', 'language', 'introduction', 'resideCity', 'resideTime', 'country', 'code', 'rcity', 'addr', 'userGender');


        $query = $this->db->query("select * from user_v2 as u1 LEFT JOIN user_v2_userinfo as u2 on u1.uid = u2.uid  WHERE u1.uid ={$uid}");
        $userInfo = $query->row_array();

        $baseInfo = array();
        foreach ($key_user_info as $v) {
            $baseInfo[$v] = empty($userInfo[$v]) ? '' : $userInfo[$v];
        }
        foreach ($key_info as $v) {
            $baseInfo[$v] = empty($userInfo[$v]) ? '' : $userInfo[$v];
        }

        if ($baseInfo['identityName'] == '留学生') {
            $data = explode('-|-', $baseInfo['identityErea']);
            $baseInfo['identityErea_zhuanye'] = empty($data[false]) ? '' : $data[false];
            $baseInfo['identityErea_school'] = empty($data[1]) ? '' : $data[1];
        }

        $lang = array();
        foreach (explode(',', $userInfo['language']) as $v) {
            if ($v == 1) {
                $lang[] = '中文';
            } elseif ($v == 2) {
                $lang[] = '法文';
            } elseif ($v == 3) {
                $lang[] = '英文';
            }
        }
        $baseInfo['language'] = $lang;

        $userFamily = empty($userInfo['userFamily']) ? '' : $userInfo['userFamily'];
        $userName = empty($userInfo['userName']) ? '' : $userInfo['userName'];
        $baseInfo['realName'] = $userFamily . $userName;

        return $baseInfo;
    }


    public function exchange_rate($type="EUR")
    {

        if (empty($exchange_rate)) {
            $url = "http://apis.haoservice.com/lifeservice/exchange/rmbquot?key=100722bd81a64c3fb5985c525a51b913";
            $exchange_rate = file_get_contents($url);
            if ($exchange_rate) {
                $exchange_rate = json_decode($exchange_rate, true);
            }
        }
        foreach ($exchange_rate['result'] as $v) {
            if ($v['code'] == $type) {
                return $v;
            }
        }
    }
}